﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QuanLyDuAn.DataAccess;
using System.Data.SqlClient;
using System.Data;

namespace QuanLyDuAn.BUS
{

    class BackupDb
    {
        SqlCommand cmd;
        SqlDataAdapter da;
        SqlConnection conn;
        SqlDataReader reader;
        dbAccess database = new dbAccess();
        public void BackupData(String fileName)
        {
            String path = "E:\\Studying\\Quản trị dự án\\backup\\";
            conn = database.GetConnect();
            conn.Open();
            string sqlStmt = String.Format("BACKUP DATABASE QuanLyDuAn TO DISK='"+path+fileName+"'");
            cmd = new SqlCommand(sqlStmt, conn);
            cmd.ExecuteNonQuery();
            conn.Close();
        }
        public void RestoreData(String fileName)
        {
            conn = database.GetConnect();
            conn.Open();
            String path = "E:\\Studying\\Quản trị dự án\\backup\\"+fileName+"";
            string sqlStmt = "USE MASTER ALTER DATABASE [QuanLyDuAn] SET Single_User WITH Rollback Immediate ALTER DATABASE [QuanLyDuAn] SET Multi_User RESTORE DATABASE [QuanLyDuAn] FROM DISK = '"+path+"' WITH REPLACE";
            cmd = new SqlCommand(sqlStmt, conn);
            cmd.ExecuteNonQuery();
            conn.Close();
        }
    }
}
